package com.yoomiito.app.ui.my;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.yoomiito.app.Constant;
import com.yoomiito.app.base.App;
import com.yoomiito.app.model.IncomeTypeData;
import com.yoomiito.app.model.bean.TabBean;
import com.yoomiito.app.model.my.MyHistoryMonthInfo;
import com.yoomiito.app.present.my.activity.MyHistoryMonthPresenter;
import com.yoomiito.app.ui.fragment.my.MyHistoryMonthFragment;
import com.yoomiito.app.ui.fragment.my.MyOrderBaseFragment;
import com.yoomiito.app.utils.SpannableUtils;

import java.util.ArrayList;
import java.util.List;

public class MyHistoryMonthActivity extends MyOrderBaseActivity<MyHistoryMonthPresenter> {
    private int month;
    private int monthData;
    private List<IncomeTypeData> typeData = new ArrayList<>();

    @Override
    public MyHistoryMonthPresenter newP() {
        return new MyHistoryMonthPresenter(App.mAppConfig);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        month = getIntent().getIntExtra(Constant.KEY_MONTH,0);
        monthData = getIntent().getIntExtra(Constant.KEY_MONTH_DATA,0);
        super.initData(savedInstanceState);
        desTv.setVisibility(View.GONE);
        titleView.setCenterText(monthData + "月");

        desTitleTv.setText(monthData + "月总收入");
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) topLayout.getLayoutParams();
        layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;

        typeData.add(new IncomeTypeData("导购引流","","含淘宝、京东、智能用卡订单总收入"));
        typeData.add(new IncomeTypeData("自营商品","","含送多多礼包、赠品、礼包、优品、爆品、课程订单总收入"));
        typeData.add(new IncomeTypeData("其它","","含管理津贴、市场补贴、活动奖励等其它收入"));
        mIncomeTypeView.intiView(typeData);
    }

    @Override
    protected List<MyOrderBaseFragment> getAllFragment() {
        List<MyOrderBaseFragment> list = new ArrayList<>();
        MyHistoryMonthFragment monthFm = new MyHistoryMonthFragment();
        Bundle monthBundle = new Bundle();
        monthBundle.putInt(Constant.KEY_MONTH,month);
        monthBundle.putInt(Constant.KEY_MONTH_DATA,monthData);
        monthFm.setArguments(monthBundle);
        list.add(monthFm);
        return list;
    }

    @Override
    protected List<TabBean> getTabList() {
        return null;
    }

    public void setData(MyHistoryMonthInfo data){
        if (data != null){
            moneyTv.setText(""+data.getTotalIncome());
            typeData.get(0).setValue(data.getTaobaoIncome()+"");
            typeData.get(1).setValue(data.getVipIncome()+"");
            typeData.get(2).setValue(SpannableUtils.saleNum2(data.getOthersIncome()));
            mIncomeTypeView.updateData(typeData);
        }
    }
}
